package second.little

import scala.util.Random

/**
  * Created by feng on 24/11/2018.
  */
object CaseDemo1 extends App{

  val array = Array("a","b","c")
  val name = array(Random.nextInt(array.length))
  name match {
    case "a" => println("aa")
    case "b" => println("ab")
    case "c" => println("ac")
  }
  println("====")


  val arr = Array("hello",1,3.0,CaseDemo1)
//  val v = arr(Random.nextInt(arr.length))
  val v = arr(3)

  v match {
    case x:Int => println("Int "+x)
    case y:Double => println("Double "+y)
    case z:String => println("String "+z)
    case CaseDemo1 => println("demo ")
    case _ => throw new Exception("not match exception")
  }

  println("====")

  val aab = Array(1,3,5)
  aab match {
    case Array(1,x,y)=>println(s"first:$x,$y")
    case Array(0)=>println("00")
    case Array(0,_*)=>println("0...")
    case _=>println("else")
  }

  println("====list====")

  val list = List(3,-1)
  list match {
    case 0::Nil => println("0")
    case x::y::Nil => println("11")
    case 0::tail => println("0 tail")
    case _ => println("else")
  }

  println("====tup====")

  val tuple1 = (2,3,7)
  tuple1 match {
    case (2,x,y) => println("0")
    case (_,z,5) => println("1")
    case _ => println("else")

  }

}




